<%@ page language="java" pageEncoding="utf-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>影院资料列表</title>
    <jsp:include page="/IncludeJS.jsp"></jsp:include>
</head>
<body>
<script type="text/javascript">
    $(function () {
        var pager = $(".easyui-datagrid").datagrid('getPager');
        $(pager).pagination({
            total:${pager.totalRows},
            pageSize:${pager.pageRow},
            displayMsg: '{from}-{to}/{total}',
            pageNumber:${pager.cur_page},
            afterPageText: '页，共{pages}页',
            pageList: [100, 500, 1000, 10000],
            loading: false,
            showPageList: true,
            showRefresh: true,
            //刷新方法
            onBeforeRefresh: function (p, s) {
                location.href = "${pageContext.request.contextPath }/agent/list?cur_page=" + p + "&pageRow=" + s;
            },
            onSelectPage: function (p, s) {
                location.href = "${pageContext.request.contextPath }/agent/list?cur_page=" + p + "&pageRow=" + s;
            }
        });
        $('#changesize').datagrid('resize', {
            height: document.body.clientHeight - 45
        });
    });

    function edit() {
        var ids = $('input[name="id"]:checked');
        var len = ids.length;
        if (ids.length == 0) {
            alert("请选择要修改的影院");
            return;
        }
        if (ids.length > 1) {
            alert("只能选择一个影院");
            return;
        }
        var arr = "";
        ids.each(function (i, d) {
            if ((i + 1) != len) {
                arr += $(d).val() + ",";
            } else {
                arr += $(d).val();
            }
        })
        url = "${pageContext.request.contextPath }/agent/update?agentId=" + arr;
        location.href = url;
    }

    function getRowData(value, rec) {
        var id = rec.id;
    }

    function save() {
        document.forms[1].submit();
    }

    function add() {
        var url = "${pageContext.request.contextPath }/agent/add";
        // var title="区域新增";
        // addTab1(title, url);
        location.href = url;
    }

    function del() {
        var ids = $('input[name="id"]:checked');
        var len = ids.length;
        if (ids.length == 0) {
            alert("请选择要删除的影院");
            return;
        }
        if (!confirm('删除影院将会删除影院下面所有影厅等信息，请确认')) {
            return;
        }
        var arr = "";
        ids.each(function (i, d) {
            if ((i + 1) != len) {
                arr += $(d).val() + ",";
            } else {
                arr += $(d).val();
            }
        })
        var url = "${pageContext.request.contextPath }/agent/del?ids=" + arr;
        location.href = url;
    }

    function changeProvince(provid) {
        var url = "${pageContext.request.contextPath }/agent/cityList";
        $.post(
            url,
            {
                "provinceId": provid
            },
            function (data) {
                $("#cityId").empty();
                $("#cityId").append("<option value='0'>不选择</option>");
                $.each(data.cityList, function (i, item) {
                    $("#cityId").append("<option value='" + item.cityId + "'>" + item.cityName + "</option>");
                });
            },
            "json"
        );
    }

    if ("${msg}" != null && "${msg}".length > 0) {
        alert("${msg}");
    }
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0"
       BACKGROUND="${pageContext.request.contextPath }/images/maintitle.jpg" class="tablelist2">
    <form action="${pageContext.request.contextPath }/agent/list" method="post">
        <tr class="tableselect2">
            <td align="left">
                <div class="tools">
                    <ul class="toolbar">
                        <li class="click"><a href="javascript:void(0);" onclick="add();"><span><img
                                src="${pageContext.request.contextPath }/images/add.png"></span>添加</a></li>
                        <li class="click"><a href="javascript:void(0);" onclick="edit();"><span><img
                                src="${pageContext.request.contextPath }/images/Mod.png"></span>修改</a></li>
                        <li><a href="javascript:void(0);" onclick="del();"><span><img
                                src="${pageContext.request.contextPath }/images/delete.png"></span>删除</a></li>
                    </ul>
                </div>
            </td>
            <td align="right">
                省份名称
                <select name="provinceId" id="provinceId" onchange="changeProvince(this.value);" style="width:150px">
                    <option value="0">请选择</option>
                    <c:forEach items="${provinceList}" var="v">
                        <c:if test="${agent.provinceId == v.provinceId}">
                            <option value="${v.provinceId}" selected>${v.provinceName}</option>
                        </c:if>
                        <c:if test="${agent.provinceId != v.provinceId}">
                            <option value="${v.provinceId}">${v.provinceName}</option>
                        </c:if>
                    </c:forEach>
                </select>
                城市名称
                <select name="cityId" id="cityId" style="width:150px">
                    <option value="0">请选择</option>
                    <c:forEach items="${cityList}" var="v">
                        <c:if test="${agent.cityId == v.cityId}">
                            <option value="${v.cityId}" selected>${v.cityName}</option>
                        </c:if>
                        <c:if test="${agent.cityId != v.cityId}">
                            <option value="${v.cityId}">${v.cityName}</option>
                        </c:if>
                    </c:forEach>
                </select>
                影院名称<input type="text" name="agentName" id="agentName" value="${agent.agentName}"/>
                <input type="submit" value="查询">
            </td>
        </tr>
    </form>
</table>
<table class="easyui-datagrid" pagination="true" id="changesize" style="width:auto;padding:0px" singleSelect="false"
       data-options="onClickRow:getRowData">
    <thead>
    <tr>
        <th field="id" checkbox="true" width=50>选择</th>
        <th field="agentName" width=200 align="center">影院名称</th>
        <th field="provinceName" width=80 align="center">省份</th>
        <th field="cityName" width=80 align="center">城市</th>
        <th field="contact" width=100 align="center">联系人</th>
        <th field="mobile" width=120 align="center">联系电话</th>
        <th field="invalid" width=80 align="center">是否有效</th>
        <th field="carPark" width=100 align="center">停车服务</th>
        <th field="glasses" width=100 align="center">3D眼镜</th>
        <th field="children" width=100 align="center">儿童优惠</th>
        <th field="registerTime" width=100 align="center">入驻日期</th>
        <th field="address" width=200 align="center">地址</th>

    </tr>
    </thead>
    <tbody>
    <c:forEach items="${pager.data}" var="v">
        <tr>
            <td>${v.agentId }</td>
            <td>${v.agentName }</td>
            <td>${v.provinceName }</td>
            <td>${v.cityName }</td>
            <td>${v.contact }</td>
            <td>${v.mobile }</td>
            <td>
                <c:if test="${v.invalid==0}">禁用</c:if>
                <c:if test="${v.invalid==1}">启用</c:if>
            </td>
            <td>${v.carPark}</td>
            <td>${v.glasses }</td>
            <td>${v.children }</td>
            <td>${v.registerTime }</td>
            <td>${v.address }</td>
        </tr>
    </c:forEach>
    </tbody>
</table>
</body>
</html>